var ws = member_id = spage = travel_ids = '';
document.addEventListener('plusready',function(){
	ws = plus.webview.currentWebview();
	spage = ws.spage;
	travel_ids = ws.travel_ids;
	member_id = plus.storage.getItem('id');
	$.ajax({
		type:"post",
		url:apiRoot + "?act=member_travel&op=travel_list",
		data:{
			member_id:member_id
		},
		dataType:'json',
		success:function(data){
			console.log(JSON.stringify(data));
			if(data.code == 200){
				if(data.datas.length > 0){
					var html = '';
					$.each(data.datas, function(k,v) {
						html += '<span class="travel_xz" data-travel_id="'+ v.travel_id +'"><li class="mui-table-view-cell mui-media mui-col-xs-3 mui-col-sm-3">'+ v.travel_name +'</li>'+
								'<li class="mui-table-view-cell mui-media mui-col-xs-2 mui-col-sm-2">'+ v.travel_type +'</li>'+
								'<li class="mui-table-view-cell mui-media mui-col-xs-5 mui-col-sm-5 mui-ellipsis">'+ v.travel_phone +'</li></span>'+
								'<li class="mui-table-view-cell mui-media mui-col-xs-2 mui-col-sm-2 edit" data-travel_id="'+ v.travel_id +'">'+
									'<i class="iconfont gray">&#xe60f;</i>'+
								'</li>';
					});
					$('.travel').html(html);
				} 
				$('.edit').unbind('tap');
				$('.edit').on('tap',function(){
					var _this = $(this);
					var travel_id = _this.attr('data-travel_id');
					var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
					var webviewContent= plus.webview.create('./Edit_contacts.html','Edit_contacts.html',{},{travel_id:travel_id,spage:ws.id});//后台创建webview并打开show.html
					webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
				        nwaiting.close(); //新webview的载入完毕后关闭等待框
				        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
				    }, false);
				});
				
				$('.travel_xz').unbind('tap');
				$('.travel_xz').on('tap',function(){
//					console.log(spage);
					if(spage){
						var _this = $(this);
						var travel_id = _this.attr('data-travel_id');
//						console.log(travel_ids+'--'+travel_id);
						if(travel_ids.indexOf(travel_id) >= 0){
							toast('该出行人已存在！请不要重复添加！');return;
						}
						$.ajax({
							type:"post",
							url:apiRoot + "?act=member_travel&op=travel_one",
							data:{
								member_id:member_id,
								travel_id:travel_id
							},
							dataType:'json',
							success:function(data){
								if(data.code == 200){
									toast('选择成功！');
									var pid = plus.webview.getWebviewById(spage);
									mui.fire(pid,'travel',{data:data.datas})
									setTimeout(function(){
										ws.close();
									},10)
								}else{
									toast('选择失败！');
								}
							},
							error:function(e){
								toast('选择失败！');
							}
						})
					}
				});
			}else{
				toast(data.datas.error);
			}
		},
		error:function(e){
			
		}
	});
	
	
	
	
	
	
//	//退出登录
//	$('.tclogin').on('click',function(){
//		var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
//		var webviewContent= plus.webview.create('./login.html','login.html',{},{spage:1});//后台创建webview并打开show.html
//		webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
//	        nwaiting.close(); //新webview的载入完毕后关闭等待框
//	        webviewContent.show("slide-in-right",20); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
//	    }, false);
//	})
},false);
function newly_added(){
	var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
	var webviewContent= plus.webview.create('./Newly_increased.html','Newly_increased.html',{},{spage:ws.id});//后台创建webview并打开show.html
	webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
        nwaiting.close(); //新webview的载入完毕后关闭等待框
        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
    }, false);
}
